import request from "@/utils/request";
import { secret } from "@/utils/secret";
import md5 from "md5"
export class User {
  //列表
  static list = () => request({
    url: "/users/list",
    method: "get",
  })

  //注册
  static register = (obj) => request({
    url:"/users/register",
    method: "GET",
     // 加密
     params: {
      username: obj.name,
      phone: obj.phone,
      time: obj.data,  //日期框
      password: md5(obj.password + secret)
    }
  })

  //查找
  static find = (name) => request({
    url: "/users/select",
    method: "post",
    data: {
      username: name
    }
  })

  //更新
  static update = (id, obj) => request({
    url: "/users/update",
    method: "post",
    data: {
      id,
      username: obj.name,
      phone: obj.phone,
      time: obj.data,
      password: obj.password
      // checkedkeys:JSON.stringify(obj.path)
    }
  })

  //更新路由
  static updatePath = (id, path) => request({
    url: "/users/update",
    method: "post",
    data: {
      id,
      checkedkeys: JSON.stringify(path)
    }
  })

  //分页
  static page = (pageNum, limit) => request({
    url: "/users/getlist",
    method: "get",
    params: {
      pageNum,
      limit
    }
  })

  //删除
  static del = (id) => request({
    url: "/users/delete",
    method: "post",
    data: {
      id
    }
  })

  //添加
  static add = (obj) => request({
    url: "/users/add",
    method: "post",
    data: {
      username: obj.name,
      phone: obj.phone,
      time: obj.data,  //日期框
      password: obj.password
    }
  })
  static changeUserInfo = (oriusername,username, attrpath) => request({
    url: '/users/changeattr',
    method: "GET",
    params: {
      oriusername:oriusername,
      username: username,
      attrpath: attrpath
    }
  })
  static downattr = (filename) => request({
    url: '/users/downattr',
    method: "GET",
    params: {
      filename: filename
    }
  })
}